package study.actorOf

import akka.actor.{Actor, Props}
import study.msg.{Fire, Push, Run, RunTask}

/**
 * @Description: context.actorOf() 创建子actor
 * @Author: DJJ
 * @Date: 2019/12/12 15:18
 */
class ShoppingCart extends Actor{

  override def postRestart(reason: Throwable): Unit = {
    println("postRestart")
  }

  override def postStop(): Unit = {
    println(" postStop")
  }

  override def preStart(): Unit = {
    println("preStart")
  }

  override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
    println("preRestart")
  }
  override def receive: Receive = {
    case Run( msg)=>println(" run :"+msg)
    case "stop"=>
      context.stop(self)
      //context.system.terminate()
    case RunTask(time)=>
      println("启动时间:"+time.getTime)
      /**
       *  这样创建的actor对象为ShoppingCart的子actor
       */
      val shop = context.actorOf(Props[Shop],"Shop")
      shop ! Fire("开始")

    case Push(msg)=>println("ShoppingCart 接收到消息:"+msg)
  }
}
